<template>
	<view class="wanlshop-classify-container">
		
		<block v-if="categoryStyle === 1">
			<scroll-view :style="{height: `${mainHeight}px`}" scroll-y class="wanlshop-classify-container__one">
				<view class="item" v-for="(item,index) in categoryData" :key="item.id"
					@tap="handleProduct(item.id, item.name)">
					<image :src="$wanlshop.oss(item.image, 350, 150)" class="list-image" />
					<view class="category-title">
						<view>{{ item.description }}</view>
						<text class="text-sm text-bold text-black">- {{language==1? item.hname:language==2? item.wname: item.name }} -</text>
					</view>
				</view>
			</scroll-view>
		</block>
		
		<block v-else-if="categoryStyle === 2">
			<scroll-view class="wanlshop-classify-container__grid" :style="{height: `${mainHeight}px`}" scroll-y>
				<view class="cu-list grid col-3 no-border">
					<view class="cu-item" v-for="(item,index) in categoryData" :key="item.id"
						@tap="handleProduct(item.id, item.name)">
						<image :src="$wanlshop.oss(item.image, 80, 80)" class="list-image" />
						<text>{{language==1? item.hname:language==2? item.wname: item.name }}</text>
					</view>
					<view class="safeAreaBottom"></view>
				</view>
			</scroll-view>
		</block>
		<block v-else-if="categoryStyle === 3">
			<view class="wanlshop-classify-container__list">
				<scroll-view scroll-y scroll-with-animation class="left" :scroll-top="scrollTop"
					:style="{ height: `${mainHeight}px` }">
					<view v-for="(item,index) in categoryData" :key="item.id" class="item"
						:class="[currentTab == index ? 'active' : '']" :data-current="index" @tap.stop="handleNav">
						<text>{{language==1? item.hname:language==2? item.wname: item.name }}</text>
					</view>
				</scroll-view>
				<block v-for="(item,index) in categoryData" :key="item.id">
					<scroll-view scroll-y class="right" :style="{ height: `${mainHeight}px` }"
						v-if="currentTab == index">
						<view class="list-cat">
							<swiper class="screen-swiper square-dot" indicator-dots circular autoplay interval="4000"
								duration="500" v-if="adverData && adverData[item.id]">
								<swiper-item v-for="(adverts, adindex) in adverData[item.id]" :key="adindex"
									@tap="onAdvert(adverts)">
									<image lazy-load class="radius-bock" :src="$wanlshop.oss(adverts.media, 350, 0, 1)"
										mode="aspectFill"></image>
								</swiper-item>
							</swiper>
							<view class="padding-top-sm">
								<view class="list-item">
									<view class="list-container">
										<view class="list-box" v-for="(category, infokey) in item.childlist"
											:key="category.id" @tap="handleProduct(category.id, category.name)">
											<image lazy-load :src="$wanlshop.oss(category.image, 60, 60)"
												class="list-image" />
											<view class="text-sm">{{language==1? category.hname:language==2? category.wname: category.name }}</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</block>
			</view>
		</block>
		<block v-else-if="categoryStyle === 4">
			<view class="wanlshop-classify-container__list">
				<scroll-view scroll-y scroll-with-animation class="left" :scroll-top="scrollTop"
					:style="{ height: `${mainHeight}px`}">
					<view v-for="(item,index) in categoryData" :key="item.id" class="item"
						:class="[currentTab == index ? 'active' : '']" :data-current="index" @tap.stop="handleNav">
						<text>{{language==1? item.hname:language==2? item.wname: item.name }}</text>
					</view>
					<view class="edgeInsetBottom"></view>
				</scroll-view>
				<block v-for="(item, index) in categoryData" :key="item.id">
					<scroll-view scroll-y class="right" :style="{ height: `${mainHeight}px` }"
						v-if="currentTab == index">
						<view class="list-cat">
							<!-- <swiper class="screen-swiper square-dot" indicator-dots circular autoplay interval="4000"
								duration="500" v-if="adverData && adverData[item.id]">
								<swiper-item v-for="(adverts, adindex) in adverData[item.id]" :key="adindex"
									@tap="onAdvert(adverts)">
									<image lazy-load class="radius-bock" :src="$wanlshop.oss(adverts.media, 350, 0, 1)"
										mode="aspectFill"></image>
								</swiper-item>
							</swiper> -->
							<view class="padding-top-sm">
								<view class="list-item" v-for="(childlist, childkey) in item.childlist"
									:key="childlist.id">
									<view class="flex justify-between title1"
										@tap="handleProduct(childlist.id, childlist.name)">
										<text>{{language==1? childlist.hname:language==2? childlist.wname: childlist.name }}</text>
										<!-- <text class="wlIcon-fanhui2 wanl-gray-light"></text> -->
									</view>
									<view class="list-container">
										<view class="list-box" v-for="(category, infokey) in childlist.childlist"
											:key="category.id" @tap="handleProduct(category.id, category.name)">
											<image lazy-load :src="$wanlshop.oss(category.image, 60, 60)"
												class="list-image" />
											<view class="text-sm" style="opacity: .8;">
											{{language==1? category.hname:language==2? category.wname: category.name }}
											</view>
										</view>
									</view>
								</view>
								<view class="edgeInsetBottom"></view>
							</view>
						</view>
						<view class="dx">
							—{{$getText('我是有底线的') }}—
						</view>
					</scroll-view>
				</block>
			</view>
		</block>
	</view>
</template>

<script>
	
	export default {
		name: 'wanlShopClassify',
		props: {
			shopId: {
				type: Number,
				default: 0
			},
			categoryStyle: {
				type: Number,
				default: 1
			},
			mainHeight: {
				type: Number,
				default: 0
			},
			adverData: {
				type: Object,
				default () {}
			},
			categoryData: {
				type: Array,
				default: () => {
					return []
				}
			},
			language: {
				type: Number,
				default: 0
			},
		},
		
		data() {
			return {
				currentTab: 0, //预设当前项的值
				scrollTop: 0, //tab标题的滚动条位置
			}
		},
		methods: {
			// 点击标题切换当前页时改变样式
			handleNav(e) {
				let cur = e.currentTarget.dataset.current;
				if (this.currentTab == cur) {
					return false;
				} else {
					this.currentTab = cur;
					this.checkCor();
				}
			},
			handleProduct(category_id, category_name) {
				if (this.shopId === 0) {
					this.$wanlshop.to(
						`/pages/product/list?data=${JSON.stringify({ category_id: category_id, category_name: category_name })}`
					);
				} else {
					this.$wanlshop.to(
						`/pages/shop/product/list?shop_id=${this.shopId}&category_id=${category_id}&category_name=${category_name}`
					);
				}
			},
			//判断当前滚动超过一屏时，设置tab标题滚动条。
			checkCor() {
				if (this.currentTab > 7) {
					this.scrollTop = 500;
				} else {
					this.scrollTop = 0;
				}
			}
		}
	}
</script>

<style lang="scss">
	.wanlshop-classify-container {
		&__one {
			padding-left: 25rpx;
			padding-right: 25rpx;
			padding-bottom: 100rpx;
			padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);

			image {
				width: 100%;
				height: 300rpx;
				border-radius: 15rpx;
				overflow: hidden;
			}

			.item {
				position: relative;
				display: flex;
				justify-content: center;
				margin-top: 25rpx;

				.category-title {
					font-size: 26rpx;
					position: absolute;
					bottom: 20rpx;
					border-radius: 10rpx;
					overflow: hidden;
					color: #666666;
					background-color: rgba(255, 255, 255, .6);
					width: 60%;
					text-align: center;
					padding: 4rpx 0;
				}
			}
		}

		&__grid {
			padding-bottom: 100rpx;
			padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);

			.cu-list {
				background-color: rgba(255, 255, 255, 0);

				&>.cu-item {
					padding: 25rpx 0;
					align-items: center;

					image {
						width: 160rpx;
						height: 160rpx;
						margin-bottom: 10rpx;
					}
				}
			}
		}

		&__list {
			display: flex;

			.left {
				width: 172rpx;
				z-index: 10;
				background: #F9F9F9;

				// overflow: hidden;

				.item {
					width: 172rpx;
					height: 103rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 26rpx;
					color: #333333;
					font-weight: 500;
					// border-radius: 0rpx 18rpx 0rpx 0rpx;
					font-weight: 600;

					&.active {
						position: relative;
						background: white;

						&::before {
							content: '';
							position: absolute;
							border-left: 12rpx solid #000000;
							height: 39rpx;
							left: 0;
						}
					}
				}
			}

			.right {
				width: 100%;
				padding-left: 30rpx;
				box-sizing: border-box;
				background-color: #fff;

				/* background-image: linear-gradient(#fff, #f2f2f2, #f4f4f4, #f6f6f6); */
				.list-cat {
					width: 100%;
					overflow: hidden;
					padding-top: 10rpx;
					padding-right: 14rpx;
					box-sizing: border-box;
				}

				.screen-swiper {
					min-height: 180rpx;
					height: 180rpx;
					overflow: hidden;
				}

				.list-item {
					background: #ffffff;
					width: 100%;
					box-sizing: border-box;
					// padding: 20rpx;
					margin-bottom: 20rpx;

					.title {
						color: #FF4F00;
					}
				}

				.list-container {
					/* padding-top: 20rpx; */
					display: flex;
					display: -webkit-flex;
					justify-content: flex-start;
					flex-direction: row;
					flex-wrap: wrap;
				}

				.list-box {
					width: 164rpx;
					text-align: center;
					padding: 20rpx 0 22rpx;
					background-color: #F9F9F9;
					margin-bottom: 12rpx;
					margin-right: 12rpx;
				}

				.list-image {
					width: 120rpx;
					height: 120rpx;
					background-color: #F9F9F9;
					margin-bottom: 12rpx;
				}
			}
		}
	}

	.title1 {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 33rpx;
		color: #333333;
		position: relative;
		margin-bottom: 24rpx;
		font-weight: 600;

		&::after {
			content: '';
			position: absolute;
			width: 64rpx;
			height: 7rpx;
			background: linear-gradient(90deg, #B2B2B2 0%, #FFFFFF 100%);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			left: 0;
			bottom: 0;
		}
	}

	.dx {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 18rpx;
		color: #999999;
		text-align: center;
		padding: 35rpx 0 70rpx;
	}
</style>